package com.itheima.jdspider;

import com.itheima.jdspider.pojo.Item;
import com.itheima.jdspider.util.C3p0Utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

public class JDItemDao {
    //保存数据
    public void saveItem(List<Item> list) throws SQLException {
        Connection conn = C3p0Utils.getConnection();
        String sql="insert into jd_item values(null,?,?,?,?,?,?,?,?)";
        PreparedStatement prep=conn.prepareStatement(sql);
        for(Item item:list){
            prep.setLong(1,item.getSpu());
            prep.setLong(2,item.getSku());
            prep.setString(3,item.getTitle());
            prep.setDouble(4,item.getPrice());
            prep.setString(5,item.getPic());
            prep.setString(6,item.getUrl());
            prep.setString(7,item.getCreated());
            prep.setString(8,item.getUpdated());

            prep.executeUpdate();
        }

        C3p0Utils.closeAll(prep,conn);
    }
}
